<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Fit Layout</title>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    <script src="../../../scripts/jquery.min.js"></script>
    <script src="../../../scripts/miniui/miniui.js"></script>
    <link href="../../../scripts/miniui/themes/default/miniui.css" rel="stylesheet">
    <link href="../../../scripts/miniui/themes/icons.css" rel="stylesheet">
    <link href="../../../scripts/miniui/themes/pure/skin.css" rel="stylesheet">
    <script src="../../../scripts/core.js"></script>

</head>
<body>
<style type="text/css">
    html, body {
        margin: 0;
        padding: 0;
        border: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
    }
</style>
<div class="mini-toolbar" style="padding:2px;border-bottom:0;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">

                <a class="mini-button" iconCls="icon-save" onclick="pass()" plain="true">通过</a>
                <a class="mini-button" iconCls="icon-cancel" onclick="reject()" plain="true">拒绝</a>

            </td>
            <td style="white-space:nowrap;">
                <input class="mini-combobox" emptyText="提现状态" id="withdrawStatus" showNullItem="false"
                       style="width:150px;"
                       textField="text"
                       url="../../../data/withdraw.js"
                       valueField="id"/>
                <input class="mini-textbox" emptyText="关键字" id="key" onenter="onKeyEnter" style="width:150px;"/>
                <a class="mini-button" onclick="search()">查询</a>
            </td>
        </tr>
    </table>
</div>
<!--撑满页面-->
<div class="mini-fit">

    <mini-datagrid _dataField="data111" allowCellEdit="true" allowCellSelect="true"
                   allowResize="true" allowSortColumn="false"
                   class="mini-datagrid"
                   id="datagrid1" idField="id" multiSelect="true"
                   pageSize="100" showSortIcon="true"
                   style="width:100%;height:100%;"
                   url="/cmsapi/business/getAllByParam">
        <columns>
            <column type="indexcolumn"></column>
            <column type="checkcolumn"></column>
            <column field="id" headerAlign="center" name="id" width="150">
                提现订单id
            </column>
            <column field="nick" width="100">昵称
            </column>
            <column field="userId" width="100">用户id
            </column>
            <column field="blockType" headerAlign="center" width="120">提现网络
            </column>
            <column field="walletLocation" headerAlign="center" width="120">钱包地址
            </column>
            <column field="copyAddress">
            </column>
            <column field="name" headerAlign="center" name="id">
                代币名称
            </column>
            <column field="money" headerAlign="center" width="120">数量

            </column>
            <column field="copyMoney">
            </column>
            <column field="createTime" width="100">订单时间

            </column>
            <column field="passTime" headerAlign="center" width="120">审核通过时间

            </column>
            <column field="status">提现状态

            </column>
        </columns>
    </mini-datagrid>

</div>

<script type="text/javascript">

    var auth = GetParams()
    mini.parse();
    var grid = mini.get("datagrid1");
    grid.setAjaxOptions({
        headers: {"userId": auth.userId, "token": auth.token}
    });


    grid.on("cellclick", function (e) {
        var record = e.record,
            column = e.column,
            field = e.field,
            value = e.value;

        //将性别文本替换成图片
        if (column.field == "copyAddress") {
            copyElementIdToClipboard(record.walletLocation)
        }
        //将性别文本替换成图片
        if (column.field == "copyMoney") {
            copyElementIdToClipboard(record.money)
        }
    });


    grid.on("drawcell", function (e) {
        var record = e.record,
            column = e.column,
            field = e.field,
            value = e.value;
        //格式化日期
        if (field == "createTime") {
            if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
        }
        //格式化日期
        if (field == "passTime") {
            if (mini.isDate(value)) e.cellHtml = mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
        }
        //将性别文本替换成图片
        if (column.field == "copyAddress") {
            e.cellHtml = '<img style="width:10px;height:10px;"  src="../../../data/copy.png"  alt="Smiley face">';
        }
        //将性别文本替换成图片
        if (column.field == "copyMoney") {
            e.cellHtml = '<img style="width:10px;height:10px;"  src="../../../data/copy.png"  alt="Smiley face">';
        }
    });

    grid.load({
        "BTC": false,
        "status": 1
    });


    function pass() {
        if (grid.getSelecteds().length == 0) return;
        var rows = grid.getSelecteds();

        var idArray = [];

        for (let i = 0; i < rows.length; i++) {
            idArray.push(rows[i].id);
        }
        $.ajax({
            url: "/cmsapi/business/pass",
            data: mini.encode(idArray),
            type: "post",
            contentType: 'application/json',
            headers: {"userId": auth.userId, "token": auth.token},
            success: function (text) {
                var resp = mini.decode(text)
                if (resp.code == 200) {
                    grid.reload();
                } else {
                    //mini.alert("错误码:" + resp.code);
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });

    }

    function reject() {
        if (grid.getSelecteds().length == 0) return;
        var rows = grid.getSelecteds();

        var idArray = [];

        for (let i = 0; i < rows.length; i++) {
            idArray.push(rows[i].id);
        }
        $.ajax({
            url: "/cmsapi/business/reject",
            data: mini.encode(idArray),
            type: "post",
            contentType: 'application/json',
            headers: {"userId": auth.userId, "token": auth.token},
            success: function (text) {
                var resp = mini.decode(text)
                if (resp.code == 200) {
                    grid.reload();
                } else {
                    //mini.alert("错误码:" + resp.code);
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });

    }

    function copyElementIdToClipboard(address) {
        try {
            // 复制到剪贴板
            navigator.clipboard.writeText(address)
                .then(() => {

                })
                .catch(err => {
                    console.error('复制失败:', err);

                });

            return true;
        } catch (error) {
            console.error('操作出错:', error);
            return false;
        }
    }

    function search() {
        var key = mini.get("key").getValue();
        var obj = mini.get("withdrawStatus");

        grid.load({
            status: obj.getValue(),
            BTC: false
        });
    }
</script>

</body>
</html>